<?php
    class user extends MY_Controller{
        
        // constructer
        public function __construct() {
    		parent::__construct();
    		$this -> load -> model('users_model');
    	}

        // action regist
        function register(){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "";
            // validate error
            $validate = 1;
            $this -> load -> helper('email');
            // get data from method post or get
            $ApiKey = $this -> input -> get_post('ApiKey');
    		$data['name'] = $this -> input -> get_post('name');
    		$data['userName'] = $this -> input -> get_post('userName');
    		$data['email'] = $this -> input -> get_post('email');
    		$data['password'] = $this -> input -> get_post('password');
    		$data['city'] = $this -> input -> get_post('city');
    		if(empty($data['city'])){
    			$data['city'] = '';
    		}
    		
    		$data['state'] = $this -> input -> get_post('state');
    		if(empty($data['state'])){
    			$data['state'] = '';
    		}
    		
    		$data['company'] = $this -> input -> get_post('company');
    		if(empty($data['company'])){
    			$data['company'] = '';
    		}
            // validate ApiKey, if ApiKey != 'android' then show error
            if($ApiKey != 'android'){
                $json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "Bad API key";
            } 
            
            // validate username and validate username exist database
            // if exist then show message error
            if (empty($data['userName'])) {
    			$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Username is required";
    		}
        	// Check the email
			if(empty($data['email'])){
				$json_data['status'] = "400";
				$validate = 0;
				$json_data['message'] = $json_data['message'] . "\n Email is required";
			}
        	else if (!valid_email($data['email'])) {
				$json_data['status'] = "400";
				$validate = 0;
				$json_data['message'] = $json_data['message'] . "\n Email must be an email address";
			}
        	// Check last name
			if(empty($data['name'])){
				$json_data['status'] = "400";
				$validate = 0;
				$json_data['message'] = $json_data['message'] . "\n Name is required";
			}
			// Check password
			if(empty($data['password'])){
				$json_data['status'] = "400";
				$validate = 0;
				$json_data['message'] = $json_data['message'] . "\n Password is required";
			}
			
			if (strlen($data['password']) < 6) {
				$json_data['status'] = "400";
				$validate = 0;
				$json_data['message'] = $json_data['message'] . "\n Password must have at least 6 characters.";
			}
	        
			if($validate == 1){
				if ($this -> users_model -> is_exist_username($data['userName']) == true) {
					$json_data['status'] = "403";
					$validate = 0;
					$json_data['message'] = $json_data['message'] . "\n Username is existed";
				}
			}
			
            if ($validate == 1) {
    			$result = $this -> users_model -> insert($data);
    			// var_dump($result);
    			if ($result != 0) {
    				$json_data['status'] = "200";
    				$json_data['message'] = "Register successfully.";
    				
    				// Compose content to send email
    				// send an email  
					$this->load->library('email');  
					$this->email->from('testshiftbuddy','Team ShiftBuddy');  
					$this->email->to($data['email']);  
					$this->email->subject('Activate your account from ShiftBuddy');  
					$this->email->message("Welcome to Shift Buddy!!!");  
					$this->email->send(); 
    			} else {
    				$json_data['status'] = "400";
    				$json_data['message'] = "Register unsuccessfully.";
    			}
    		}
            $this -> print_json($json_data);
        }
        
        // action form regist
        function regist(){
            $this->load->view('user');
        }

        // action find a friend
        function findafriend(){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "Successfully";
            $json_data['status'] = "200";
            $json_data['result'] = array();
            // validate error
            $validate = 1;
            // get data from method post or get
            $ApiKey = $this -> input -> get_post('ApiKey');
            $data['friendName'] = $this -> input -> get_post('friendName');
            $data['authToken'] = $this -> input -> get_post('authToken');
            
            // Check api key as "android" text
            if($ApiKey != 'android'){
            	$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Bad API key";
            }
            
            // Check auth token expired
            if($this->users_model->check_expire_auth_token($data['authToken']) == FALSE){
            	$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Auth token is invalid";
            }
            
            // Check friend name
            if (empty($data['friendName'])) {
    			$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Friend name is required";
    		}
    		if($validate == 1){
    			$cur_name = $this->users_model->get_user_from_auth_token($data['authToken']);
    			$cur_name = $cur_name[0]['user_name'];
	    		$result = $this->users_model->search_member_name($data['friendName'], $cur_name);
	    		//echo $result;
	    		if(count($result) <= 0){
	    			
	    		}else{
	    			foreach ($result as $key => $value){
	    				$item = "";
	    				$status = "";
	    				if($value['user_name1'] == NULL && $value['user_name2'] == NULL){
	    					$status = "0";
	    				}else if($value['user_name'] == $value['user_name1']){
	    					if($value['state'] == 0){ // Request
	    						$status = "1";
	    					}else{
	    						if($value['sharing'] == 0){
	    							$status = "4";
	    						}else{
	    							$status = "3";
	    						}
	    					}
	    				}else{
		    				if($value['state'] == 0){ // Request
		    						$status = "2";
		    				}else{
		    					if($value['sharing'] == 0){
		    						$status = "4";
		    					}else{
		    						$status = "3";
		    					}
		    				}
	    				}
	    				$item = array("userName" => $value['user_name'], "name" => $value['name'], "status" => $status);
	    				array_push($json_data['result'], $item);
	    			}
	    		}
    		}
            $this -> print_json($json_data);
        }
        
        // action friend request
        function friendrequest(){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "";
            $json_data['responseCode'] = "200";
            $json_data['status'] = "200";
            // validate error
            $validate = 1;
            // get data from method post or get
            $ApiKey = $this -> input -> get_post('ApiKey');
            $data['friendName'] = $this -> input -> get_post('friendName');
            $data['authToken'] = $this -> input -> get_post('authToken');
            
            // Check api key as "android" text
            if($ApiKey != 'android'){
            	$json_data['responseCode'] = "400";
            	$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Bad API key";
            }
            
            // Check auth token expired
            if($this->users_model->check_expire_auth_token($data['authToken']) == FALSE){
            	$json_data['responseCode'] = "401";
            	$json_data['status'] = "401";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Auth token is invalid";
            }
            
            // Check friend name
            if (empty($data['friendName'])) {
    			$json_data['responseCode'] = "400";
    			$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Friend name is required";
    		}
    		// Check friend name exist in database
    		$result = $this->users_model->is_exist_username($data['friendName']);
    		if($result == false){
    			$json_data['responseCode'] = "404";
    			$json_data['status'] = "404";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Supplied email is not registered";
    		}
    		// Get user_id from auth_token
    		$cur_name = '';
    		if($validate == 1){
    			$cur_name = $this->users_model->get_user_from_auth_token($data['authToken']);
    			$cur_name = $cur_name[0]['user_name'];
    		}
    		if($validate == 1){
    			$result = $this->users_model->is_has_been_request_username($data['friendName'], $cur_name);
    			if($result == true){
    				$json_data['responseCode'] = "400";
	    			$json_data['status'] = "400";
	    			$validate = 0;
	    			$json_data['message'] = $json_data['message'] . "\n The friend request has been created before";
    			}
    		}
    		if($validate == 1){
	    		// Insert to relationship table
	    		$this->users_model->insert_relationship_state($cur_name, $data['friendName']);
                
                // include lib gcm
                include_once './application/utils/GCM.php';
                $gcm = new GCM();
                
                $result = $this->users_model->get_push_token_by_username($data['friendName']);
                $pushToken = $result[0]['pushToken'];
                
                $registatoin_ids = array($pushToken);
                $message = $cur_name." want make your friend";
                $message = array("price" => $message);
        
                $result = $gcm->send_notification($registatoin_ids, $message);
                $json_data['message'] = $result;
    		}
    		// Update state to buddy_relationship
            $this -> print_json($json_data);
        }
        
    	// action find a friend
        function responsefriendrequest($state){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "";
            $json_data['status'] = "200";
            // validate error
            $validate = 1;
            // get data from method post or get
            $ApiKey = $this -> input -> get_post('ApiKey');
            $data['friendName'] = $this -> input -> get_post('friendName');
            $data['authToken'] = $this -> input -> get_post('authToken');
            
            // Check api key as "android" text
            if($ApiKey != 'android'){
            	$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Bad API key";
            }
            
            // Check auth token expired
            if($this->users_model->check_expire_auth_token($data['authToken']) == FALSE){
            	$json_data['status'] = "401";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Auth token is invalid";
            }
            
            // Check friend name
            if (empty($data['friendName'])) {
    			$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Friend name is required";
    		}
    		// Check friend name exist in database
    		$result = $this->users_model->is_exist_username($data['friendName']);
    		if($result == false){
    			$json_data['status'] = "404";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Friend name is not exist";
    		}
    		if($validate == 1){
    			// Get user_id from auth_token
	    		$cur_name = $this->users_model->get_user_from_auth_token($data['authToken']);
	    		$cur_name = $cur_name[0]['user_name'];
	    		
	    		// Check friend name is requested from another user name
	    		$result = $this->users_model->is_request_username($data['friendName'], $cur_name);
	        	if($result == false){
	    			$json_data['status'] = "404";
	    			$validate = 0;
	    			$json_data['message'] = $json_data['message'] . "\n Friend name has not been requested before";
    			}
    		}
    		if($validate == 1){
				// Update table buddy_relationshipe    		
	    		$result = $this->users_model ->update_relationship_state($data['friendName'], $data['authToken'], $state);
	    		if($result == false){
	    			$json_data['status'] = "404";
	    			$validate = 0;
	    		}else{
	    			$json_data['message'] = "Successfully";
	    		}
    		}
    		// Update state to buddy_relationship
            $this -> print_json($json_data);
        }
        
        // Action Accept friend request
        function acceptfriendrequest(){
        	
        	$this -> responsefriendrequest(1);
        }
        
        // Action Ignore friend request
        function ignorefriendrequest(){
        	$this -> responsefriendrequest(2);
        }
    	// permit sharing
        function permitsharing($sharing){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "";
            $json_data['status'] = "200";
            // validate error
            $validate = 1;
            // get data from method post or get
            $ApiKey = $this -> input -> get_post('ApiKey');
            $data['friendName'] = $this -> input -> get_post('friendName');
            $data['authToken'] = $this -> input -> get_post('authToken');
            
            // Check api key as "android" text
            if($ApiKey != 'android'){
            	$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Bad API key";
            }
            
            // Check auth token expired
            if($this->users_model->check_expire_auth_token($data['authToken']) == FALSE){
            	$json_data['status'] = "401";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Auth token is invalid";
            }
            
            // Check friend name
            if (empty($data['friendName'])) {
    			$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Friend name is required";
    		}
    		
    		if($validate == 1){
    			// Get current user name
    			$cur_name = $this->users_model->get_user_from_auth_token($data['authToken']);
    			$cur_name = $cur_name[0]['user_name'];
				// Update table buddy_relationshipe
	    		$result = $this->users_model ->update_relationship_sharing($data['friendName'], $cur_name, $sharing);
	    		if($result == false){
	    			$json_data['status'] = "404";
	    			$validate = 0;
	    		}else{
	    			$json_data['message'] = "Successfully";
	    		}
    		}
    		// Update state to buddy_relationship
            $this -> print_json($json_data);
        }
        // action enable sharing
        function enablesharing(){
        	$this -> permitsharing(1);
        }
        // action disable sharing
        function disablesharing(){
        	$this -> permitsharing(0);
        }
        
        	// permit sharing
        function getlistfriends(){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "";
            $json_data['status'] = "200";
            $json_data['result'] = array();
            // validate error
            $validate = 1;
            // get data from method post or get
            $ApiKey = $this -> input -> get_post('ApiKey');
            $data['authToken'] = $this -> input -> get_post('authToken');
            
            // Check api key as "android" text
            if($ApiKey != 'android'){
            	$json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Bad API key";
            }
            
            // Check auth token expired
            if($this->users_model->check_expire_auth_token($data['authToken']) == FALSE){
            	$json_data['status'] = "401";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Auth token is invalid";
            }
            
    		if($validate == 1){
    			// Get current user name
    			$cur_name = $this->users_model->get_user_from_auth_token($data['authToken']);
    			$cur_name = $cur_name[0]['user_name'];
				// Update table buddy_relationshipe
	    		$result = $this->users_model ->get_friend_pending_request($cur_name);
	    		if(count($result) <= 0){
	    			
	    		}else{
	    			foreach ($result as $key => $value){
	    				$status = "0";
	    				$userName = "";
	    				if($value['state'] == 1){
	    					if($value['user_name1'] == $cur_name){
	    						$userName = $value['user_name2'];
	    					}else{
	    						$userName = $value['user_name1'];
	    					}
	    					if($value['sharing'] == 1){
	    						$status = "1";
	    					}else{
	    						$status = "2";
	    					}
	    					
	    				}else {
	    					if($value['user_name1'] == $cur_name){
	    						$userName = $value['user_name2'];
	    						$status = "3";
	    					}else{
	    						$userName = $value['user_name1'];
	    						$status = "0";
	    					}
	    				}
	    				$item = array("name" => $value['name'], "userName" => $userName, "status" => $status);
	    				array_push($json_data['result'], $item);
	    			}
	    		}
    		}
    		// Update state to buddy_relationship
            $this -> print_json($json_data);
        }
        // action login
        function login(){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "";
            // validate error
            $validate = 1;
            // get data from method post or get
            $ApiKey = $this -> input -> get_post('ApiKey');
            $data['userName'] = $this -> input -> get_post('userName');
            $data['password'] = $this -> input -> get_post('password');
            $data['pushToken'] = $this -> input -> get_post('pushToken');
            
            // validate username is not null
            if(empty($data['userName'])){
                $json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\n Username is required";
            }
            
            // validate password is not null
            if(empty($data['password'])){
                $json_data['status'] = "400";
    			$validate = 1;
    			$json_data['message'] = $json_data['message'] . "\n Password is required";
            }
            // validate ApiKey, if ApiKey != 'android' then show error
            if($ApiKey != 'android'){
                $json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\nBad API key";
            }
            
            if ($validate == 1) {
    			$result = $this->users_model->get_user($data);
    			// var_dump($result);
    			if ($result == FALSE) {
    				$json_data['status'] = "401";
    				$json_data['message'] = "Login fail.";
    			} else {
                    // update pushToken for user
                    $this->users_model->update_token_user($data);
                    
                    // get auth_token
                    $auth_token = $this->getAccessToken($data['userName']);
                    
                    $data_insert_auth_token = array();
                    $data_insert_auth_token['user_name'] = $data['userName'];
                    $data_insert_auth_token['auth_token'] = $auth_token;
                    $data_insert_auth_token['ins_dt'] = date("Y-m-d H:i:s", time());
                    // insert data to auth_token
                    $insert = $this->users_model->insert_auth_token($data_insert_auth_token);
                                          
    				$json_data['status'] = "200";
                    $json_data['message'] = "Login successfull";
    				$json_data['authToken'] = $auth_token;
    			}
    		}
            $this -> print_json($json_data);
        }
        
        function logout(){
            // array data for insert database
            $data = array();
            // array json data for return message
            $json_data['message'] = "";
            // validate error
            $validate = 1;
            
            $ApiKey = $this -> input -> get_post('ApiKey');
            $data['userName'] = $this -> input -> get_post('userName');
            $data['authToken'] = $this->input->get_post('authToken');
            
            // validate ApiKey, if ApiKey != 'android' then show error
            if($ApiKey != 'android'){
                $json_data['status'] = "400";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\nBad API key";
            }
            
            $expire_token = $this->users_model->check_expire_auth_token($data['authToken']);
            if($expire_token == FALSE){
                $json_data['status'] = "401";
    			$validate = 0;
    			$json_data['message'] = $json_data['message'] . "\nToken is expired";
            }
            
            if ($validate == 1) {
                $this->users_model->update_auth_token($data);
                $json_data['status'] = "200";
                $json_data['message'] = "Sign out success";
            }
            
            $this -> print_json($json_data);
        }
        
        // get auth_token
        private function getAccessToken($username){
    		$flag_false = false;
    		$access_token = '';
            
    		while(!$flag_false) {
    			$access_token = sha1(uniqid() . $username . mt_rand());
    			$ret = false;
    			
                $ret = $this->users_model->check_token($access_token);
    			
    			if(!$ret) {
    				$flag_false = true;
    			}
    		}
		
		return $access_token;
	}
    
    public function saveshift(){
        // array data for insert database
        $data = array();
        // array json data for return message
        $json_data['message'] = "";
        // validate error
        $validate = 1;
        
        $ApiKey = $this -> input -> get_post('ApiKey');
        $data['authToken'] = $this->input->get_post('authToken');
        $data['shift'] = $this->input->get_post('shift');
        $decodeJsonShift = json_decode($data['shift']);
        
        // validate ApiKey, if ApiKey != 'android' then show error
        if($ApiKey != 'android'){
            $json_data['status'] = "400";
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nBad API key";
        }
        
        $expire_token = $this->users_model->check_expire_auth_token($data['authToken']);
        if($expire_token == FALSE){
            $json_data['status'] = "401";
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nToken is expired";
        }
        
        if ($validate == 1) {
			// Get current user name
    		$userName = $this->users_model->get_user_from_auth_token($data['authToken']);
            $this->users_model->save_shift($decodeJsonShift, $userName[0]['user_name']);
            $json_data['status'] = "200";
            $json_data['message'] = "Success";
    	}
        
        $this -> print_json($json_data);
    }
    public function getfriendsshifts(){
        // array data for insert database
        $data = array();
        // array json data for return message
        $json_data['message'] = "";
        $json_data['result'] = array();
        // validate error
        $validate = 1;
        
        $ApiKey = $this -> input -> get_post('ApiKey');
        $data['authToken'] = $this->input->get_post('authToken');
        $data['date'] = $this->input->get_post('date');
        
        // validate ApiKey, if ApiKey != 'android' then show error
        if($ApiKey != 'android'){
            $json_data['status'] = "400";
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nBad API key";
        }
        
        $expire_token = $this->users_model->check_expire_auth_token($data['authToken']);
        if($expire_token == FALSE){
            $json_data['status'] = "401";
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nToken is expired";
        }
        if(empty($data['date'])){
        	if($validate == 1){
        		$json_data['status'] = "201";
        	}
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nDate parameter is requested";
        }
        if ($validate == 1) {
			// Get current user name
    		$userName = $this->users_model->get_user_from_auth_token($data['authToken']);
            $result = $this->users_model->get_friend_shift($data['date'], $userName[0]['user_name']);
        	if(count($result) <= 0){
	    			
    		}else{
    			foreach ($result as $key => $value){
    				$item = "";
    				if($value['shift_range'] == 'Day Off' || $value['shift_range'] == ''){
    					$item = array("friendName" => $value['username'], "isDayOff" => "true");
    				}else{
    					$pieces = explode("-", $value['shift_range']);
    					if(count($pieces) == 2){
    						$item = array("friendName" => $value['username'], "isDayOff" => "false", "startTime" => trim($pieces[0]), "endTime" => trim($pieces[1]));
    					}else{
    						$item = array("friendName" => $value['username'], "isDayOff" => "false", "startTime" => trim($pieces[0]), "endTime" => "");
    					}
    				}
    				array_push($json_data['result'], $item);
    			}
    		}
            $json_data['status'] = "200";
            $json_data['message'] = "Success";
    	}
        
        $this -> print_json($json_data);
    }
    
    public function getyourshifts(){
        // array data for insert database
        $data = array();
        // array json data for return message
        $json_data['message'] = "";
        $json_data['result'] = array();
        // validate error
        $validate = 1;
        
        $ApiKey = $this -> input -> get_post('ApiKey');
        $data['authToken'] = $this->input->get_post('authToken');
        $data['date'] = $this->input->get_post('date');
        
        // validate ApiKey, if ApiKey != 'android' then show error
        if($ApiKey != 'android'){
            $json_data['status'] = "400";
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nBad API key";
        }
        
        $expire_token = $this->users_model->check_expire_auth_token($data['authToken']);
        if($expire_token == FALSE){
            $json_data['status'] = "401";
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nToken is expired";
        }
        
        if(empty($data['date'])){
        	if($validate == 1){
        		$json_data['status'] = "201";
        	}
			$validate = 0;
			$json_data['message'] = $json_data['message'] . "\nDate parameter is requested";
        }
        
        if ($validate == 1) {
			// Get current user name
    		$userName = $this->users_model->get_user_from_auth_token($data['authToken']);
            $result = $this->users_model->get_my_shift($userName[0]['user_name'], $data['date']);
        	if(count($result) > 0){
    			foreach ($result as $key => $value){
    				$item = "";
    				if($value['shift_range'] == 'Day Off' || $value['shift_range'] == ''){
    					$item = array("date" => $value['date'], "isDayOff" => "true", "startTime" => "", "endTime" => "", "note" => $value['note'], "colorId" => $value['color_id']);
    				}else{
    					$pieces = explode("-", $value['shift_range']);
    					if(count($pieces) == 2){
    						$item = array("date" => $value['date'], "isDayOff" => "false", "startTime" => trim($pieces[0]), "endTime" => trim($pieces[1]), "note" => $value['note'], "colorId" => $value['color_id']);
    					}else{
    						$item = array("date" => $value['date'], "isDayOff" => "false", "startTime" => trim($pieces[0]), "endTime" => "", "note" => $value['note'], "colorId" => $value['color_id']);
    					}
    				}
    				array_push($json_data['result'], $item);
    			}
    		}
            $json_data['status'] = "200";
            $json_data['message'] = "Success";
    	}
        
        $this -> print_json($json_data);
    }
    
    public function testgcm(){
        // include lib gcm
        include_once './application/utils/GCM.php';
        $gcm = new GCM();
        
        // array data for insert database
        $data = array();
        $data['pushToken'] = $this->input->get_post('pushToken');
        $data['message'] = $this->input->get_post('message');
        
        //$pushToken = 'APA91bHAM0bILGueMj1vmeGxNSL3Fk4NkZ09a3lGShl32QocSqthceAPVERg8C-I7gT31ZBl4xOs2dSu-c8H_Pfy9g0iFmnMjJIZscUTYr_xxl63dKFdRf4Osk8mZdhJNFPciFGPo23oDnlUmvJHLnHnepXcgjrX9w';
        
        $registatoin_ids = array($data['pushToken']);
        $message = array("price" => $data['message']);

        $result = $gcm->send_notification($registatoin_ids, $message);
        echo $result;
    }
    
    public function index()
	{
		$this->load->view('login');
	}    
        // action form login
        function frmLogin(){
            $this->load->view('login');
        }
    }
?>